<!DOCTYPE html>
<!-- saved from url=(0057)https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8 -->
<html lang="en" class=" is-u2f-enabled"><head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object# article: http://ogp.me/ns/article# profile: http://ogp.me/ns/profile#"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    

    <link crossorigin="anonymous" href="选择器 · d3_d3 Wiki_files/frameworks-c07e6f4b02b556d1d85052fb3853caf84c80e6b23dcdb1ae1b00f051da1115a2.css" integrity="sha256-wH5vSwK1VtHYUFL7OFPK+EyA5rI9zbGuGwDwUdoRFaI=" media="all" rel="stylesheet">
    <link crossorigin="anonymous" href="选择器 · d3_d3 Wiki_files/github-09e1c38d593bf8fc6e4c4f1b526d0184e27c433d64963942c1e8c361589f8125.css" integrity="sha256-CeHDjVk7+PxuTE8bUm0BhOJ8Qz1kljlCwejDYVifgSU=" media="all" rel="stylesheet">
    
    
    
    

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Language" content="en">
    <meta name="viewport" content="width=device-width">
    
    <title>选择器 · d3/d3 Wiki</title>
    <link rel="search" type="application/opensearchdescription+xml" href="https://github.com/opensearch.xml" title="GitHub">
    <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub">
    <link rel="apple-touch-icon" href="https://github.com/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="57x57" href="https://github.com/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="https://github.com/apple-touch-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="https://github.com/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="https://github.com/apple-touch-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="https://github.com/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="https://github.com/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="https://github.com/apple-touch-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="https://github.com/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="https://github.com/apple-touch-icon-180x180.png">
    <meta property="fb:app_id" content="1401488693436528">

      <meta content="https://avatars1.githubusercontent.com/u/1562726?v=3&amp;s=400" name="twitter:image:src"><meta content="@github" name="twitter:site"><meta content="summary" name="twitter:card"><meta content="d3/d3" name="twitter:title"><meta content="d3 - Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:" name="twitter:description">
      <meta content="https://avatars1.githubusercontent.com/u/1562726?v=3&amp;s=400" property="og:image"><meta content="GitHub" property="og:site_name"><meta content="object" property="og:type"><meta content="d3/d3" property="og:title"><meta content="https://github.com/d3/d3" property="og:url"><meta content="d3 - Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:" property="og:description">
      <meta name="browser-stats-url" content="https://api.github.com/_private/browser/stats">
    <meta name="browser-errors-url" content="https://api.github.com/_private/browser/errors">
    <link rel="assets" href="https://assets-cdn.github.com/">
    <link rel="web-socket" href="wss://live.github.com/_sockets/VjI6MTQyMzUxMDM1OmYwMGUyMTg1NTY2NzczMThiYzJkNzMzMDZkMzY1M2VjZDVkMjk1MjE5MmNmMTNhYTI4NDI1NmVhNmZmMTIxNTI=--8ef141468ff5f74051d0a6a49455725c7c8a03a4">
    <meta name="pjax-timeout" content="1000">
    <link rel="sudo-modal" href="https://github.com/sessions/sudo_modal">
    <meta name="request-id" content="E314:7557:1932486:295992A:58845307" data-pjax-transient="">

    <meta name="msapplication-TileImage" content="/windows-tile.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="selected-link" value="repo_wiki" data-pjax-transient="">

    <meta name="google-site-verification" content="KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r1XQysX3xurLU">
<meta name="google-site-verification" content="ZzhVyEFwb7w3e0-uOTltm8Jsck2F5StVihD0exw2fsA">
    <meta name="google-analytics" content="UA-3769691-2">

<meta content="collector.githubapp.com" name="octolytics-host"><meta content="github" name="octolytics-app-id"><meta content="E314:7557:1932486:295992A:58845307" name="octolytics-dimension-request_id"><meta content="18323475" name="octolytics-actor-id"><meta content="defenderhhhh" name="octolytics-actor-login"><meta content="70592ef2d225e449076dd88e6b12c145017fd92eccf81e729a16009ced6970cb" name="octolytics-actor-hash">
<meta content="/<user-name>/<repo-name>/wiki/show" data-pjax-transient="true" name="analytics-location">



  <meta class="js-ga-set" name="dimension1" content="Logged In">



        <meta name="hostname" content="github.com">
    <meta name="user-login" content="defenderhhhh">

        <meta name="expected-hostname" content="github.com">
      <meta name="js-proxy-site-detection-payload" content="MjJjZWJjOWY3OWM1N2ZhNDk0ZmU0NjY5MDVjZTUyZTg5ZDk5OWQ1YzE0Y2M4Mzg3M2RlNDM5YjA3OTU2NDFlOHx7InJlbW90ZV9hZGRyZXNzIjoiMjIyLjE4MC4xNjAuMTU0IiwicmVxdWVzdF9pZCI6IkUzMTQ6NzU1NzoxOTMyNDg2OjI5NTk5MkE6NTg4NDUzMDciLCJ0aW1lc3RhbXAiOjE0ODUwNjcwMTYsImhvc3QiOiJnaXRodWIuY29tIn0=">


      <link rel="mask-icon" href="https://assets-cdn.github.com/pinned-octocat.svg" color="#000000">
      <link rel="icon" type="image/x-icon" href="https://assets-cdn.github.com/favicon.ico">

    <meta name="html-safe-nonce" content="7da07f67fa3bc09c6326a894464ac00a14a92cab">

    <meta http-equiv="x-pjax-version" content="94a9cc48ead92329faac49833ac14041">
    

      
  <meta name="description" content="d3 - Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:">
  <meta name="go-import" content="github.com/d3/d3 git https://github.com/d3/d3.git">

  <meta content="1562726" name="octolytics-dimension-user_id"><meta content="d3" name="octolytics-dimension-user_login"><meta content="943149" name="octolytics-dimension-repository_id"><meta content="d3/d3" name="octolytics-dimension-repository_nwo"><meta content="true" name="octolytics-dimension-repository_public"><meta content="false" name="octolytics-dimension-repository_is_fork"><meta content="943149" name="octolytics-dimension-repository_network_root_id"><meta content="d3/d3" name="octolytics-dimension-repository_network_root_nwo">
  <link href="https://github.com/d3/d3/commits/master.atom" rel="alternate" title="Recent Commits to d3:master" type="application/atom+xml">


  <style type="text/css"></style></head>


  <body class="logged-in  env-production windows vis-public">
    <div id="js-pjax-loader-bar" class="pjax-loader-bar"><div class="progress"></div></div>
    <a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#start-of-content" tabindex="1" class="accessibility-aid js-skip-to-content">Skip to content</a>

    
    
    



        <div class="header header-logged-in true" role="banner">
  <div class="container clearfix">

    <a class="header-logo-invertocat" href="https://github.com/" data-hotkey="g d" aria-label="Homepage" data-ga-click="Header, go to dashboard, icon:logo">
  <svg aria-hidden="true" class="octicon octicon-mark-github" height="28" version="1.1" viewBox="0 0 16 16" width="28"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
</a>


        <div class="header-search scoped-search site-scoped-search js-site-search" role="search">
  <!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="https://github.com/d3/d3/search" class="js-site-search-form" data-scoped-search-url="/d3/d3/search" data-unscoped-search-url="/search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div>
    <label class="form-control header-search-wrapper js-chromeless-input-container">
      <div class="header-search-scope">This repository</div>
      <input type="text" class="form-control header-search-input js-site-search-focus js-site-search-field is-clearable" data-hotkey="s" name="q" placeholder="Search" aria-label="Search this repository" data-unscoped-placeholder="Search GitHub" data-scoped-placeholder="Search" autocapitalize="off">
    </label>
</form></div>


      <ul class="header-nav float-left" role="navigation">
        <li class="header-nav-item">
          <a href="https://github.com/pulls" aria-label="Pull requests you created" class="js-selected-navigation-item header-nav-link" data-ga-click="Header, click, Nav menu - item:pulls context:user" data-hotkey="g p" data-selected-links="/pulls /pulls/assigned /pulls/mentioned /pulls">
            Pull requests
</a>        </li>
        <li class="header-nav-item">
          <a href="https://github.com/issues" aria-label="Issues you created" class="js-selected-navigation-item header-nav-link" data-ga-click="Header, click, Nav menu - item:issues context:user" data-hotkey="g i" data-selected-links="/issues /issues/assigned /issues/mentioned /issues">
            Issues
</a>        </li>
          <li class="header-nav-item">
            <a class="header-nav-link" href="https://gist.github.com/" data-ga-click="Header, go to gist, text:gist">Gist</a>
          </li>
      </ul>

    
<ul class="header-nav user-nav float-right" id="user-links">
  <li class="header-nav-item">
    

  </li>

  <li class="header-nav-item dropdown js-menu-container">
    <a class="header-nav-link tooltipped tooltipped-s js-menu-target" href="https://github.com/new" aria-label="Create new…" data-ga-click="Header, create new, icon:add">
      <svg aria-hidden="true" class="octicon octicon-plus float-left" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 9H7v5H5V9H0V7h5V2h2v5h5z"></path></svg>
      <span class="dropdown-caret"></span>
    </a>

    <div class="dropdown-menu-content js-menu-content">
      <ul class="dropdown-menu dropdown-menu-sw">
        
<a class="dropdown-item" href="https://github.com/new" data-ga-click="Header, create new repository">
  New repository
</a>

  <a class="dropdown-item" href="https://github.com/new/import" data-ga-click="Header, import a repository">
    Import repository
  </a>

<a class="dropdown-item" href="https://gist.github.com/" data-ga-click="Header, create new gist">
  New gist
</a>

  <a class="dropdown-item" href="https://github.com/organizations/new" data-ga-click="Header, create new organization">
    New organization
  </a>



  <div class="dropdown-divider"></div>
  <div class="dropdown-header">
    <span title="d3/d3">This repository</span>
  </div>
    <a class="dropdown-item" href="https://github.com/d3/d3/issues/new" data-ga-click="Header, create new issue">
      New issue
    </a>

      </ul>
    </div>
  </li>

  <li class="header-nav-item dropdown js-menu-container">
    <a class="header-nav-link name tooltipped tooltipped-sw js-menu-target" href="https://github.com/defenderhhhh" aria-label="View profile and more" data-ga-click="Header, show menu, icon:avatar">
      <img alt="@defenderhhhh" class="avatar" height="20" src="选择器 · d3_d3 Wiki_files/18323475" width="20">
      <span class="dropdown-caret"></span>
    </a>

    <div class="dropdown-menu-content js-menu-content">
      <div class="dropdown-menu dropdown-menu-sw">
        <div class="dropdown-header header-nav-current-user css-truncate">
          Signed in as <strong class="css-truncate-target">defenderhhhh</strong>
        </div>

        <div class="dropdown-divider"></div>

        <a class="dropdown-item" href="https://github.com/defenderhhhh" data-ga-click="Header, go to profile, text:your profile">
          Your profile
        </a>
        <a class="dropdown-item" href="https://github.com/defenderhhhh?tab=stars" data-ga-click="Header, go to starred repos, text:your stars">
          Your stars
        </a>
        <a class="dropdown-item" href="https://github.com/explore" data-ga-click="Header, go to explore, text:explore">
          Explore
        </a>
          <a class="dropdown-item" href="https://github.com/integrations" data-ga-click="Header, go to integrations, text:integrations">
            Integrations
          </a>
        <a class="dropdown-item" href="https://help.github.com/" data-ga-click="Header, go to help, text:help">
          Help
        </a>

        <div class="dropdown-divider"></div>

        <a class="dropdown-item" href="https://github.com/settings/profile" data-ga-click="Header, go to settings, icon:settings">
          Settings
        </a>

        <!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="https://github.com/logout" class="logout-form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="lgZ0u7YOG3Eh9MfOJa9PuX8jvA7SkLD1PibST24feMB8lAlobAHPlpAQouAbSvgKWiodL4JeI+7yDE6NvkwGXw=="></div>
          <button type="submit" class="dropdown-item dropdown-signout" data-ga-click="Header, sign out, icon:logout">
            Sign out
          </button>
</form>      </div>
    </div>
  </li>
</ul>


    
  </div>
</div>


      


    <div id="start-of-content" class="accessibility-aid"></div>

      <div id="js-flash-container">
</div>


    <div role="main">
        <div itemscope="" itemtype="http://schema.org/SoftwareSourceCode">
    <div id="js-repo-pjax-container" data-pjax-container="">
      
<div class="pagehead repohead instapaper_ignore readability-menu experiment-repo-nav">
  <div class="container repohead-details-container">

    

<ul class="pagehead-actions">

  <li>
        <!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="https://github.com/notifications/subscribe" class="js-social-container" data-autosubmit="true" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="LJhU10OdAIZkbyo1fqJZj2AfCmbHzfoaevHUvNN4YWGeCDfcpAiGAv7CEokAjHBvUlKp40w0eXUq+SM1mrF0MA=="></div>      <input class="form-control" id="repository_id" name="repository_id" type="hidden" value="943149">

        <div class="select-menu js-menu-container js-select-menu">
          <a href="https://github.com/d3/d3/subscription" class="btn btn-sm btn-with-count select-menu-button js-menu-target" role="button" tabindex="0" aria-haspopup="true" data-ga-click="Repository, click Watch settings, action:wiki#show">
            <span class="js-select-button">
              <svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>
              Watch
            </span>
          </a>
          <a class="social-count js-social-count" href="https://github.com/d3/d3/watchers" aria-label="2939 users are watching this repository">
            2,939
          </a>

        <div class="select-menu-modal-holder">
          <div class="select-menu-modal subscription-menu-modal js-menu-content" aria-hidden="true">
            <div class="select-menu-header js-navigation-enable" tabindex="-1">
              <svg aria-label="Close" class="octicon octicon-x js-menu-close" height="16" role="img" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
              <span class="select-menu-title">Notifications</span>
            </div>

              <div class="select-menu-list js-navigation-container" role="menu">

                <div class="select-menu-item js-navigation-item selected" role="menuitem" tabindex="0">
                  <svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>
                  <div class="select-menu-item-text">
                    <input checked="checked" id="do_included" name="do" type="radio" value="included">
                    <span class="select-menu-item-heading">Not watching</span>
                    <span class="description">Be notified when participating or @mentioned.</span>
                    <span class="js-select-button-text hidden-select-button-text">
                      <svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>
                      Watch
                    </span>
                  </div>
                </div>

                <div class="select-menu-item js-navigation-item " role="menuitem" tabindex="0">
                  <svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>
                  <div class="select-menu-item-text">
                    <input id="do_subscribed" name="do" type="radio" value="subscribed">
                    <span class="select-menu-item-heading">Watching</span>
                    <span class="description">Be notified of all conversations.</span>
                    <span class="js-select-button-text hidden-select-button-text">
                      <svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>
                      Unwatch
                    </span>
                  </div>
                </div>

                <div class="select-menu-item js-navigation-item " role="menuitem" tabindex="0">
                  <svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>
                  <div class="select-menu-item-text">
                    <input id="do_ignore" name="do" type="radio" value="ignore">
                    <span class="select-menu-item-heading">Ignoring</span>
                    <span class="description">Never be notified.</span>
                    <span class="js-select-button-text hidden-select-button-text">
                      <svg aria-hidden="true" class="octicon octicon-mute" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8 2.81v10.38c0 .67-.81 1-1.28.53L3 10H1c-.55 0-1-.45-1-1V7c0-.55.45-1 1-1h2l3.72-3.72C7.19 1.81 8 2.14 8 2.81zm7.53 3.22l-1.06-1.06-1.97 1.97-1.97-1.97-1.06 1.06L11.44 8 9.47 9.97l1.06 1.06 1.97-1.97 1.97 1.97 1.06-1.06L13.56 8l1.97-1.97z"></path></svg>
                      Stop ignoring
                    </span>
                  </div>
                </div>

              </div>

            </div>
          </div>
        </div>
</form>
  </li>

  <li>
      <div class="js-toggler-container js-social-container starring-container ">
    <!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="https://github.com/d3/d3/unstar" class="starred" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="BfLF2Q7fgcTIr+nowt2xiEclFoh4LVUdaq11zkWk1/mysWZuKjK+ZOH4JIAjS83glwYWikc9gvlk/ZgXwETBEw=="></div>
      <button type="submit" class="btn btn-sm btn-with-count js-toggler-target" aria-label="Unstar this repository" title="Unstar d3/d3" data-ga-click="Repository, click unstar button, action:wiki#show; text:Unstar">
        <svg aria-hidden="true" class="octicon octicon-star" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74z"></path></svg>
        Unstar
      </button>
        <a class="social-count js-social-count" href="https://github.com/d3/d3/stargazers" aria-label="59436 users starred this repository">
          59,436
        </a>
</form>
    <!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="https://github.com/d3/d3/star" class="unstarred" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="+Vyr77Mnj1kI3bZKKTiYWgIXMIKKxAWWBMbz3hBFVNAsSu5oCMp9F8x6HJN4PO13tGJ46bIC2V3tTeQ7/3TIHA=="></div>
      <button type="submit" class="btn btn-sm btn-with-count js-toggler-target" aria-label="Star this repository" title="Star d3/d3" data-ga-click="Repository, click star button, action:wiki#show; text:Star">
        <svg aria-hidden="true" class="octicon octicon-star" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74z"></path></svg>
        Star
      </button>
        <a class="social-count js-social-count" href="https://github.com/d3/d3/stargazers" aria-label="59436 users starred this repository">
          59,436
        </a>
</form>  </div>

  </li>

  <li>
          <!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="https://github.com/d3/d3/fork" class="btn-with-count" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="BhUJWzsyVnjN4CAbNtV/G5ip2G1P3KxcOzubBNauJIngb6f3exu0DY0H2LR3kt4gp/JUPL4TtrAdYcd01qqJTQ=="></div>
            <button type="submit" class="btn btn-sm btn-with-count" data-ga-click="Repository, show fork modal, action:wiki#show; text:Fork" title="Fork your own copy of d3/d3 to your account" aria-label="Fork your own copy of d3/d3 to your account">
              <svg aria-hidden="true" class="octicon octicon-repo-forked" height="16" version="1.1" viewBox="0 0 10 16" width="10"><path fill-rule="evenodd" d="M8 1a1.993 1.993 0 0 0-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 0 0 2 1a1.993 1.993 0 0 0-1 3.72V6.5l3 3v1.78A1.993 1.993 0 0 0 5 15a1.993 1.993 0 0 0 1-3.72V9.5l3-3V4.72A1.993 1.993 0 0 0 8 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
              Fork
            </button>
</form>
    <a href="https://github.com/d3/d3/network" class="social-count" aria-label="15846 users forked this repository">
      15,846
    </a>
  </li>
</ul>

    <h1 class="public ">
  <svg aria-hidden="true" class="octicon octicon-repo" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M4 9H3V8h1v1zm0-3H3v1h1V6zm0-2H3v1h1V4zm0-2H3v1h1V2zm8-1v12c0 .55-.45 1-1 1H6v2l-1.5-1.5L3 16v-2H1c-.55 0-1-.45-1-1V1c0-.55.45-1 1-1h10c.55 0 1 .45 1 1zm-1 10H1v2h2v-1h3v1h5v-2zm0-10H2v9h9V1z"></path></svg>
  <span class="author" itemprop="author"><a href="https://github.com/d3" class="url fn" rel="author">d3</a></span><!--
--><span class="path-divider">/</span><!--
--><strong itemprop="name"><a href="https://github.com/d3/d3" data-pjax="#js-repo-pjax-container">d3</a></strong>

</h1>

  </div>
  <div class="container">
    
<nav class="reponav js-repo-nav js-sidenav-container-pjax" itemscope="" itemtype="http://schema.org/BreadcrumbList" role="navigation" data-pjax="#js-repo-pjax-container">

  <span itemscope="" itemtype="http://schema.org/ListItem" itemprop="itemListElement">
    <a href="https://github.com/d3/d3" class="js-selected-navigation-item reponav-item" data-hotkey="g c" data-selected-links="repo_source repo_downloads repo_commits repo_releases repo_tags repo_branches /d3/d3" itemprop="url">
      <svg aria-hidden="true" class="octicon octicon-code" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M9.5 3L8 4.5 11.5 8 8 11.5 9.5 13 14 8 9.5 3zm-5 0L0 8l4.5 5L6 11.5 2.5 8 6 4.5 4.5 3z"></path></svg>
      <span itemprop="name">Code</span>
      <meta itemprop="position" content="1">
</a>  </span>

    <span itemscope="" itemtype="http://schema.org/ListItem" itemprop="itemListElement">
      <a href="https://github.com/d3/d3/issues" class="js-selected-navigation-item reponav-item" data-hotkey="g i" data-selected-links="repo_issues repo_labels repo_milestones /d3/d3/issues" itemprop="url">
        <svg aria-hidden="true" class="octicon octicon-issue-opened" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
        <span itemprop="name">Issues</span>
        <span class="counter">0</span>
        <meta itemprop="position" content="2">
</a>    </span>

  <span itemscope="" itemtype="http://schema.org/ListItem" itemprop="itemListElement">
    <a href="https://github.com/d3/d3/pulls" class="js-selected-navigation-item reponav-item" data-hotkey="g p" data-selected-links="repo_pulls /d3/d3/pulls" itemprop="url">
      <svg aria-hidden="true" class="octicon octicon-git-pull-request" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
      <span itemprop="name">Pull requests</span>
      <span class="counter">0</span>
      <meta itemprop="position" content="3">
</a>  </span>

  <a href="https://github.com/d3/d3/projects" class="js-selected-navigation-item reponav-item" data-selected-links="repo_projects new_repo_project repo_project /d3/d3/projects">
    <svg aria-hidden="true" class="octicon octicon-project" height="16" version="1.1" viewBox="0 0 15 16" width="15"><path fill-rule="evenodd" d="M10 12h3V2h-3v10zm-4-2h3V2H6v8zm-4 4h3V2H2v12zm-1 1h13V1H1v14zM14 0H1a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1V1a1 1 0 0 0-1-1z"></path></svg>
    Projects
    <span class="counter">0</span>
</a>
    <a href="https://github.com/d3/d3/wiki" class="js-selected-navigation-item selected reponav-item" data-hotkey="g w" data-selected-links="repo_wiki /d3/d3/wiki">
      <svg aria-hidden="true" class="octicon octicon-book" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M3 5h4v1H3V5zm0 3h4V7H3v1zm0 2h4V9H3v1zm11-5h-4v1h4V5zm0 2h-4v1h4V7zm0 2h-4v1h4V9zm2-6v9c0 .55-.45 1-1 1H9.5l-1 1-1-1H2c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h5.5l1 1 1-1H15c.55 0 1 .45 1 1zm-8 .5L7.5 3H2v9h6V3.5zm7-.5H9.5l-.5.5V12h6V3z"></path></svg>
      Wiki
</a>

  <a href="https://github.com/d3/d3/pulse" class="js-selected-navigation-item reponav-item" data-selected-links="pulse /d3/d3/pulse">
    <svg aria-hidden="true" class="octicon octicon-pulse" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M11.5 8L8.8 5.4 6.6 8.5 5.5 1.6 2.38 8H0v2h3.6l.9-1.8.9 5.4L9 8.5l1.6 1.5H14V8z"></path></svg>
    Pulse
</a>
  <a href="https://github.com/d3/d3/graphs" class="js-selected-navigation-item reponav-item" data-selected-links="repo_graphs repo_contributors /d3/d3/graphs">
    <svg aria-hidden="true" class="octicon octicon-graph" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M16 14v1H0V0h1v14h15zM5 13H3V8h2v5zm4 0H7V3h2v10zm4 0h-2V6h2v7z"></path></svg>
    Graphs
</a>

</nav>

  </div>
</div>

<div class="container new-discussion-timeline experiment-repo-nav">
  <div class="repository-content">

    

<div id="wiki-wrapper" class="wiki-wrapper page">
<div class="gh-header">
  <div class="gh-header-show">
        <div class="gh-header-actions">
          <a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8/_edit" class="btn btn-sm ">Edit</a>
          <a href="https://github.com/d3/d3/wiki/_new" class="btn btn-sm btn-primary">New Page</a>
        </div>
    <h1 class="gh-header-title instapaper_title">选择器</h1>
      <div class="gh-header-meta">
        Jing Ma edited this page <relative-time datetime="2016-09-29T05:53:10Z" title="2016年9月29日 GMT+8下午1:53">on 29 Sep 2016</relative-time>
        ·
        <a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8/_history" class="history">
          29 revisions
        </a>
      </div>
  </div>
</div>
<div id="wiki-content" class="wiki-content">
  <div class="has-rightbar">

  <div id="wiki-rightbar" class="wiki-rightbar">
    <div class="wiki-pages-box readability-sidebar boxed-group flush js-wiki-pages-box " role="navigation">
      
<h3 class="js-wiki-toggle-collapse wiki-auxiliary-content">
  <svg aria-hidden="true" class="octicon octicon-triangle-down caret-expanded" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M0 5l6 6 6-6z"></path></svg>
  <svg aria-hidden="true" class="octicon octicon-triangle-right caret-collapsed" height="16" version="1.1" viewBox="0 0 6 16" width="6"><path fill-rule="evenodd" d="M0 14l6-6-6-6z"></path></svg>
  Pages <span class="counter">116</span>
</h3>
<div class="boxed-group-inner wiki-auxiliary-content wiki-auxiliary-content-no-bg">
    <div class="filter-bar">
      <input type="text" id="wiki-pages-filter" class="form-control input-sm input-block js-filterable-field" placeholder="Find a Page…" aria-label="Find a Page…" tabindex="2">
    </div>

  <ul class="wiki-pages" data-filterable-for="wiki-pages-filter" data-filterable-type="substring">
    <li>
      <strong><a href="https://github.com/d3/d3/wiki" class="wiki-page-link">Home</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/3.0" class="wiki-page-link">3.0</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/3.1" class="wiki-page-link">3.1</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/API--%E4%B8%AD%E6%96%87%E6%89%8B%E5%86%8C" class="wiki-page-link">API  中文手册</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/API-Reference" class="wiki-page-link">API Reference</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/API-Reference-(%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D1%8F%D0%B7%D1%8B%D1%87%D0%BD%D0%B0%D1%8F-%D0%B2%D0%B5%D1%80%D1%81%D0%B8%D1%8F)" class="wiki-page-link">API Reference (русскоязычная версия)</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/API-%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9" class="wiki-page-link">API リファレンス</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Arrays" class="wiki-page-link">Arrays</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Behaviors" class="wiki-page-link">Behaviors</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Bundle-Layout" class="wiki-page-link">Bundle Layout</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Chord-Layout" class="wiki-page-link">Chord Layout</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Cluster-Layout" class="wiki-page-link">Cluster Layout</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/CN-Home" class="wiki-page-link">CN Home</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Colors" class="wiki-page-link">Colors</a></strong>
    </li>
    <li>
      <strong><a href="https://github.com/d3/d3/wiki/Core" class="wiki-page-link">Core</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/CSV" class="wiki-page-link">CSV</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/CSV%E6%A0%BC%E5%BC%8F%E5%8C%96" class="wiki-page-link">CSV格式化</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Drag-Behavior" class="wiki-page-link">Drag Behavior</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Force-Layout" class="wiki-page-link">Force Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Formatting" class="wiki-page-link">Formatting</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Gallery" class="wiki-page-link">Gallery</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Geo" class="wiki-page-link">Geo</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Geo-Paths" class="wiki-page-link">Geo Paths</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Geo-Projections" class="wiki-page-link">Geo Projections</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Geo-Streams" class="wiki-page-link">Geo Streams</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Geometry" class="wiki-page-link">Geometry</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Hierarchy-Layout" class="wiki-page-link">Hierarchy Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Histogram-Layout" class="wiki-page-link">Histogram Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Hull-Geom" class="wiki-page-link">Hull Geom</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/ID-Home" class="wiki-page-link">ID Home</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Internals" class="wiki-page-link">Internals</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/JP-3.0" class="wiki-page-link">JP 3.0</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/JP-API-Reference" class="wiki-page-link">JP API Reference</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/JP-Home" class="wiki-page-link">JP Home</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/JP-Tutorials" class="wiki-page-link">JP Tutorials</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Layouts" class="wiki-page-link">Layouts</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Learning-paths" class="wiki-page-link">Learning paths</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Localization" class="wiki-page-link">Localization</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Math" class="wiki-page-link">Math</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Namespaces" class="wiki-page-link">Namespaces</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Ordinal-Scales" class="wiki-page-link">Ordinal Scales</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Pack-Layout" class="wiki-page-link">Pack Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Partition-Layout" class="wiki-page-link">Partition Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Pie-Layout" class="wiki-page-link">Pie Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Plugins" class="wiki-page-link">Plugins</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Polygon-Geom" class="wiki-page-link">Polygon Geom</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Quadtree-Geom" class="wiki-page-link">Quadtree Geom</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Quantitative-Scales" class="wiki-page-link">Quantitative Scales</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Release-Notes" class="wiki-page-link">Release Notes</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Requests" class="wiki-page-link">Requests</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Scales" class="wiki-page-link">Scales</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Selection-(russians)" class="wiki-page-link">Selection (russians)</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Selections" class="wiki-page-link">Selections</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Stack-Layout" class="wiki-page-link">Stack Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG" class="wiki-page-link">SVG</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-Axes" class="wiki-page-link">SVG Axes</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-Controls" class="wiki-page-link">SVG Controls</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-Events" class="wiki-page-link">SVG Events</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-Shapes" class="wiki-page-link">SVG Shapes</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-%E5%BD%A2%E7%8A%B6" class="wiki-page-link">SVG 形状</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-%E6%8E%A7%E4%BB%B6" class="wiki-page-link">SVG 控件</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG-%E8%BD%B4" class="wiki-page-link">SVG 轴</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/SVG%E5%87%BD%E6%95%B0" class="wiki-page-link">SVG函数</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Time" class="wiki-page-link">Time</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Time-Formatting" class="wiki-page-link">Time Formatting</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Time-Intervals" class="wiki-page-link">Time Intervals</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Time-Scales" class="wiki-page-link">Time Scales</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Transitions" class="wiki-page-link">Transitions</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Tree-Layout" class="wiki-page-link">Tree Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Treemap-Layout" class="wiki-page-link">Treemap Layout</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Tutorials" class="wiki-page-link">Tutorials</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/TW-Home" class="wiki-page-link">TW Home</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Upgrading-to-3.0" class="wiki-page-link">Upgrading to 3.0</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Voronoi-Geom" class="wiki-page-link">Voronoi Geom</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/Zoom-Behavior" class="wiki-page-link">Zoom Behavior</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%D0%92%D1%8B%D0%B1%D0%BE%D1%80%D0%BA%D0%B8" class="wiki-page-link">Выборки</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%86%85%E9%83%A8" class="wiki-page-link">内部</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%87%A0%E4%BD%95" class="wiki-page-link">几何</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%88%86%E5%8C%BA%E5%B8%83%E5%B1%80" class="wiki-page-link">分区布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%8A%9B%E5%B8%83%E5%B1%80" class="wiki-page-link">力布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%8C%85%E5%B8%83%E5%B1%80" class="wiki-page-link">包布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4" class="wiki-page-link">命名空间</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%9B%9B%E5%8F%89%E6%A0%91" class="wiki-page-link">四叉树</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%9C%B0%E7%90%86" class="wiki-page-link">地理</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%9C%B0%E7%90%86%E6%8A%95%E5%BD%B1" class="wiki-page-link">地理投影</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%9C%B0%E7%90%86%E8%B7%AF%E5%BE%84" class="wiki-page-link">地理路径</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%A0%86%E5%8F%A0%E5%B8%83%E5%B1%80" class="wiki-page-link">堆叠布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%A4%9A%E8%BE%B9%E5%BD%A2" class="wiki-page-link">多边形</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%B1%82%E6%AC%A1%E5%B8%83%E5%B1%80" class="wiki-page-link">层次布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%B8%83%E5%B1%80" class="wiki-page-link">布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%BA%8F%E6%95%B0%E6%AF%94%E4%BE%8B%E5%B0%BA" class="wiki-page-link">序数比例尺</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E5%BC%A6%E5%B8%83%E5%B1%80" class="wiki-page-link">弦布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%8B%96%E5%8A%A8" class="wiki-page-link">拖动</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%8D%86%E5%B8%83%E5%B1%80" class="wiki-page-link">捆布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%8D%86%E7%BB%91%E5%B8%83%E5%B1%80" class="wiki-page-link">捆绑布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%95%B0%E5%80%BC%E6%AF%94%E4%BE%8B%E5%B0%BA" class="wiki-page-link">数值比例尺</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%95%B0%E5%AD%A6" class="wiki-page-link">数学</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%95%B0%E7%BB%84" class="wiki-page-link">数组</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%97%B6%E9%97%B4%E6%AF%94%E4%BE%8B%E5%B0%BA" class="wiki-page-link">时间比例尺</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%9C%AC%E5%9C%B0%E5%8C%96" class="wiki-page-link">本地化</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%A0%91%E5%B8%83%E5%B1%80" class="wiki-page-link">树布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%A0%B8%E5%BF%83%E5%87%BD%E6%95%B0" class="wiki-page-link">核心函数</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%A0%BC%E5%BC%8F%E5%8C%96" class="wiki-page-link">格式化</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%AF%94%E4%BE%8B%E5%B0%BA" class="wiki-page-link">比例尺</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E6%B3%B0%E6%A3%AE%E5%A4%9A%E8%BE%B9%E5%BD%A2" class="wiki-page-link">泰森多边形</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E7%9B%B4%E6%96%B9%E5%9B%BE%E5%B8%83%E5%B1%80" class="wiki-page-link">直方图布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E7%9F%A9%E5%BD%A2%E6%A0%91%E5%B8%83%E5%B1%80" class="wiki-page-link">矩形树布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E7%B0%87%E5%B8%83%E5%B1%80" class="wiki-page-link">簇布局</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E7%BC%A9%E6%94%BE" class="wiki-page-link">缩放</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E8%A1%8C%E4%B8%BA" class="wiki-page-link">行为</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E8%AF%B7%E6%B1%82" class="wiki-page-link">请求</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E8%B5%AB%E5%B0%94" class="wiki-page-link">赫尔</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E8%BF%87%E6%B8%A1" class="wiki-page-link">过渡</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="选择器 · d3_d3 Wiki_files/选择器 · d3_d3 Wiki.html" class="wiki-page-link">选择器</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E9%A2%9C%E8%89%B2" class="wiki-page-link">颜色</a></strong>
    </li>
    <li class="wiki-more-pages">
      <strong><a href="https://github.com/d3/d3/wiki/%E9%A5%BC%E5%B8%83%E5%B1%80" class="wiki-page-link">饼布局</a></strong>
    </li>
    <li class="wiki-more-pages-link">
      <a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#" class="js-wiki-more-pages-link">
        Show 101 more pages…
      </a>
    </li>
  </ul>
</div>

    </div>


    <div class="clone-url">
      <h5>Clone this wiki locally</h5>
      <div class="input-group js-zeroclipboard-container">
        <input type="text" class="form-control input-sm text-small text-gray input-monospace js-url-field js-zeroclipboard-target" aria-label="Clone URL for this wiki" value="https://github.com/d3/d3.wiki.git" readonly="readonly">
        <span class="input-group-button">
          <button aria-label="Copy to clipboard" class="js-zeroclipboard btn btn-sm zeroclipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="button"><svg aria-hidden="true" class="octicon octicon-clippy" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path></svg></button>
        </span>
      </div>


        <a href="https://windows.github.com/" class="btn btn-sm sidebar-button" title="Save this wiki to your computer and use it in GitHub Desktop." aria-label="Save this wiki to your computer and use it in GitHub Desktop.">
          <svg aria-hidden="true" class="octicon octicon-desktop-download" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 6h3V0h2v6h3l-4 4-4-4zm11-4h-4v1h4v8H1V3h4V2H1c-.55 0-1 .45-1 1v9c0 .55.45 1 1 1h5.34c-.25.61-.86 1.39-2.34 2h8c-1.48-.61-2.09-1.39-2.34-2H15c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1z"></path></svg>
          Clone in Desktop
        </a>
    </div>
  </div>

  <div id="wiki-body" class="wiki-body gollum-markdown-content instapaper_body">
      <div class="markdown-body">
        <blockquote>
<p><a href="https://github.com/d3/d3/wiki/Home">Wiki</a> ▸ <a class="internal present" href="https://github.com/d3/d3/wiki/API--%E4%B8%AD%E6%96%87%E6%89%8B%E5%86%8C">API--中文手册</a> ▸ <a class="internal present" href="https://github.com/d3/d3/wiki/%E6%A0%B8%E5%BF%83%E5%87%BD%E6%95%B0">核心函数</a> ▸ <strong>选择器</strong></p>
</blockquote>

<ul>
<li>如发现翻译不当或有其他问题可以通过以下方式联系译者:</li>
<li>邮箱：<a href="mailto:zhang_tianxu@sina.com">zhang_tianxu@sina.com</a>
</li>
<li>QQ群：<a href="http://jq.qq.com/?_wv=1027&amp;k=239rjew">D3.js</a>:437278817，<a href="http://jq.qq.com/?_wv=1027&amp;k=S8wGMe">大数据可视化</a>：436442115</li>
<li>Github小组：<a href="https://github.com/VisualCrew">VisualCrew</a>
</li>
</ul>

<p>一个<strong>选择</strong>就是从当前文档中抽取的一组元素。D3使用<a href="http://www.w3.org/TR/css3-selectors/">CSS3</a>来选择页面元素。例如，你可以使用的选择方式有标签 ("div")、类(“.awesome”)、唯一标识符(“#foo”)、属性(“[color=red]”)、或者包含(“parent child”)。选择器可以是交叉(".this.that" 表示逻辑与)的也可以是联合的(".this, .that" 表示逻辑或)。如果你的浏览器不支持选择器，你可以在D3前包含<a href="http://sizzlejs.com/">Sizzle</a>来支持向后兼容。</p>

<p>当选择完元素之后你可以添加操作。这些操作可以设置或者获取<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#attr">属性</a>、<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#style">样式</a>、<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#property">特性</a>、<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#html">选择器</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#text">文本</a>内容。属性值等可以被指定为常量或者函数；后者为每个元素求值。你也可以为数据选择器加入到<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">data</a>操作；这个数据就可以用做数据驱动的变换的操作符。另外，加上数据产生<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#enter">enter</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#exit">exit</a>子选择器，你就可以<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#add">add</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#remove">remove</a>元素来响应数据中的改变。</p>

<p>一般来说，在D3中你不需要使用for循环后者递归来修改文档。因为你可以一次操作这个选择器而不是遍历各个元素。当然，你也可以手动地遍历各个元素，有一个<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#each">each</a>操作可以调用任意一个函数，选择器的结果是数组，所以元素可以访问(例如<code>selection[0][0]</code>)。为了简便D3支持方法链：这个操作返回值是一个选择器。</p>

<h2>
<a id="user-content-选择元素" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E9%80%89%E6%8B%A9%E5%85%83%E7%B4%A0" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>选择元素</h2>

<p>D3提供了两种高级方法来选择元素：<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_select">select</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_selectAll">selectAll</a>。这些方法接收选择器字符串。前者只返回第一个匹配的元素，后者选择在文档遍历次序中所有匹配的元素。这个方法也可以接受节点，这可以用来和第三方库例如JQuery或者开发工具(<code>$0</code>)整合。</p>

<p><a name="user-content-d3_select" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_select">#</a> d3.<b>select</b>(<i>selector</i>)</p>

<p>选中与指定选择器字符串匹配的第一个元素，返回单元素选择结果。如果当前文档中没有匹配的元素则返回空的选择。如果有多个元素被选中，只有第一个匹配的元素（在文档遍历次序中）被选中。</p>

<p><a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_select">#</a> d3.<b>select</b>(<i>node</i>)</p>

<p>选择指定的节点。如果你已经有一个节点的引用这将是很有用的。例如事件监听器中的<code>d3.select(this)</code> 或者一个全局对象例如<code>document.body</code>。这个函数不会遍历DOM树。</p>

<p><a name="user-content-d3_selectAll" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_selectAll">#</a> d3.<b>selectAll</b>(<i>selector</i>)</p>

<p>选中匹配指定选择器的所有的元素。这些元素会按照文档的遍历顺序（从上到下）选择。如果当前文档中没有匹配的元素则返回空的选择。</p>

<p><a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_selectAll">#</a> d3.<b>selectAll</b>(<i>nodes</i>)</p>

<p>选择指定的元素数组。如果你已经有了一些元素的引用这将是很有用的，例如事件监听器中的<code>d3.selectAll(this.childNodes)</code>，或者一个全局对象例如<code>document.links</code>。节点的参数不用恰好是数组；任何可以转化为一个数组的伪数组（例一个<code>NodeList</code>或者 <code>arguments</code>）都可以，这个函数不会遍历DOM树。</p>

<h2>
<a id="user-content-操作选择" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E6%93%8D%E4%BD%9C%E9%80%89%E6%8B%A9" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>操作选择</h2>

<p>选择是一组元素。D3绑定额外的方法到数组上。所以你可以在选中的元素上应用操作，例如为所有选中的元素设置属性值。一个细微的差别是选择结果是分组的，而不是一个一维数组。每一个选择都是元素数组中的一个数组。这保留了自选择的层次结果，大多数情况下你可以忽略这个细节，这就是为什么一个单一的元素选择看起来像 <code>[[node]]</code> 而不是 <code>[node]</code> 。想要了解更多关于嵌套选择的知识请参考<a href="http://bost.ocks.org/mike/nest/">嵌套选择</a>。如果你想要学习选择器是怎么工作的你可以用浏览器的开发者工具控制台交互式地访问数据。你可以检查返回数组来查看哪些元素被选中了以及它们是如何分组的。你还可以再应用操作来选择元素并查看页面内容的改变。</p>

<h3>
<a id="user-content-内容" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E5%86%85%E5%AE%B9" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>内容</h3>

<p>D3有一系列可以影响文档内容的操作。这些是你最常用来展示数据的。当操作用来设置文档内容的时候会返回当前选择，所以你就可以使用一个简单的声明将多个操作链接在一起。</p>

<p><a name="user-content-attr" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#attr">#</a> selection.<b>attr</b>(<i>name</i>[, <i>value</i>])</p>

<p>如果指定了<em>value</em>参数，将为所有选中的元素通过指定的<em>name</em>为指定的<em>value</em>设置属性。如果<em>value</em>是一个常数，那么所有的元素都将设置为相同的属性值；如果<em>value</em>是一个函数，那么这个函数会为每个选中的元素（按顺序）计算。入参是当前数据元素<code>d</code>和当前索引<code>i</code>，以及代表当前DOM元素的<code>this</code>上下文。这个函数的返回值接下来用来设置每个元素的属性。null值将移除指定的属性。</p>

<p>如果<em>value</em>参数没有指定，就会返回为选择中第一个非空（null）元素所指定的属性值。一般来说，只有当你知道选择中恰好包含一个元素时才有用。</p>

<p>指定的<em>name</em>参数也会含有一个前缀，例如<code>xlink:href</code>是用来指定Xlink命名空间中<em>href</em>属性的。默认情况下，D3支持svg、xhtml、xlink、xml和 xmlns命名空间。可以添加<a href="https://github.com/d3/d3/wiki/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4#prefix">d3.ns.prefix</a>来注册其他的命名空间。</p>

<p><em>name</em>也可以是一个<em>name</em>和<em>value</em>属性对象。</p>

<p><a name="user-content-classed" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#classed">#</a> selection.<b>classed</b>(<i>name</i>[, <i>value</i>])</p>

<p>这个操作是用来设置<em>class</em>属性值得便捷程序。它能识别<em>class</em>属性是一个按照空格分隔的标记集合。这样它就能使用<a href="https://developer.mozilla.org/en/DOM/element.classList">classList</a>（如果有的话）来方便地添加、移除和切换CSS类。</p>

<p>如果<em>value</em>属性被指定，不论是否指定类都会与选定元素相结合。如果<em>value</em>是一个常量且其值为真，那么所有的元素都会被分配指定的类（还没分配的话）。如果其值为假，那么就会移除选中元素的class（已经分配过）。如果<em>value</em>是一个函数，那么这个函数会为每个选中的元素（按顺序）计算。入参是当前数据元素<code>d</code>和当前索引<code>i</code>，以及代表当前DOM元素的<code>this</code>上下文。这个函数的返回值接下来用来分配或者不分配每个元素的class。</p>

<p>如果你想一次设置多个class可以使用一个对象，文字如同：<code>selection.classed({'foo': true, 'bar': false})</code>，或者使用以空格分隔的class列表形如：<code>selection.classed('foo bar', true)</code>。</p>

<p>如果<em>value</em>没有被指定，当且仅当选择中首个非空值有指定的class就会返回true。一般来说，只有当你知道选择中恰好包含一个元素时才有用。</p>

<p><a name="user-content-style" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#style">#</a> selection.<b>style</b>(<i>name</i>[, <i>value</i>[, <i>priority</i>]])</p>

<p>如果<em>value</em>参数被指定，通过指定名称和指定的值为所有选中的元素设置CSS样式属性。如果<em>value</em>是一个常数，那么所有的元素都设置相同的样式值；否则，如果值是一个函数，则该函数为每个选定的元件（按顺序）计算，入参是当前数据元素<code>d</code>和当前索引<code>i</code>，以及代表当前DOM元素的<code>this</code>上下文。该函数的返回值被用来设置每个元素的样式属性。 null值将删除样式属性。可选参数<em>priority</em>也可以指定，无论是null空或字符串“important”（不带感叹号）。 </p>

<p>如果你想一次设置多个样式属性，使用对象文本，如下所示：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">selection</span>.<span class="pl-c1">style</span>({<span class="pl-s"><span class="pl-pds">'</span>stroke<span class="pl-pds">'</span></span><span class="pl-k">:</span> <span class="pl-s"><span class="pl-pds">'</span>black<span class="pl-pds">'</span></span>, <span class="pl-s"><span class="pl-pds">'</span>stroke-width<span class="pl-pds">'</span></span><span class="pl-k">:</span> <span class="pl-c1">2</span>})</pre></div>

<p>如果未指定值，则返回在选择中的第一个非空元素指定样式属性的当前计算值。只有当你知道选择只包含一个元素时是很有用的。需要注意的是计算的值可能与先前设置的值不同，尤其是当样式属性使用了简写属性（如“font”样式，这是简写为"font-size"，"font-face",“等）。</p>

<p><a name="user-content-property" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#property">#</a> selection.<b>property</b>(<i>name</i>[, <i>value</i>])</p>

<p>一些HTML元素具有特殊的属性使用标准的属性或样式是不可寻址的。例如，表单文本（text）字段有一个<code>value</code>字符串属性，复选框（checkboxes）有一个<code>checked</code>布尔型属性。可以使用<code>property</code>操作符来获取或设置这些属性，，或任何其他基本元素的可寻址字段，例如<code>className</code>。</p>

<p>如果指定了<em>value</em>，就为所有选中的元素指定名称的属性设置指定的值（value）。如果值是一个常数，那么所有的元素被给予相同的属性值；如果<em>value</em>是一个函数，则该函数为每个选定的元素（按顺序）计算，入参是当前数据元素<code>d</code>和当前索引<code>i</code>，以及代表当前DOM元素的<code>this</code>上下文。该函数的返回值被用于设置每个元素的属性。空值将删除指定的属性。 </p>

<p>如果你想一次设置多个属性，可以使用对象文本，如下所示：<code>selection.property({'foo': 'bar', 'baz': 'qux'})</code>。 </p>

<p>如果未指定值，则返回在选择中第一个非空元素指定属性的值。只有当你知道选择只包含一个元素这通常是很有用的。</p>

<p><a name="user-content-text" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#text">#</a> selection.<b>text</b>([<i>value</i>])</p>

<p>文本操作符是基于<code>textContent</code>属性；设置文本内容将取代任何现有的子元素。 </p>

<p>如果指定了<em>value</em>时，设置所有选择元素的文本内容为指定的值。如果<em>value</em>是一个常数，那么所有的元素被赋予相同的文本内容；如果<em>value</em>是一个函数，则该函数被每个选定的元素（按顺序）计算，入参是当前数据元素<code>d</code>和当前索引<code>i</code>，以及代表当前DOM元素的<code>this</code>上下文。该函数的返回值被用于设置每个元素的文本内容。null值会清除内容。 </p>

<p>如果未指定<em>value</em>，则返回在选择中第一个非空元素的文本内容。只有当你知道选择只包含一个元素时这通常是很有用的。</p>

<p><a name="user-content-html" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#html">#</a> selection.<b>html</b>([<i>value</i>])</p>

<p><code>html</code>的操作基于<a href="http://dev.w3.org/html5/spec-LC/apis-in-html-documents.html#innerhtml">innerHTML</a>属性；设置内部HTML内容将取代任何现有的子元素。此外，您可能更愿意使用数据驱动的方式<code>append</code>或<code>insert</code>操作创建HTML内容;该操作符的目的是，适用于你想用少量但有丰富格式的HTML。</p>

<p>如果指定了<em>value</em>，为所有选择的元素设置在内部的HTML内容为指定的值。如果<em>value</em>是一个常数，那么所有的元素被给予相同的内部HTML内容；如果<em>value</em>是一个函数，则该函数为每个选定的元素（按顺序）计算，入参是当前数据元素<code>d</code>和当前索引<code>i</code>，以及代表当前DOM元素的<code>this</code>上下文。该函数的返回值被用于设置每个单元的内部的HTML内容。null值会清除内容。</p>

<p>如果未指定<em>value</em>，则返回在选择中第一个非空元素的内部HTML内容。只有当你知道选择只包含一个元素时这通常是很有用的。 
注：正如它的名字所暗示的，selection.html仅支持HTML元素。 SVG元素和其它非HTML元素不支持innerHTML属性，因此与selection.html不相容。请考虑使用<a href="https://developer.mozilla.org/en-US/docs/XMLSerializer">XMLSerializer</a>转换DOM树为文本。灵参见<a href="https://code.google.com/p/innersvg/">innersvg polyfill</a>，它提供了一个垫片以支持SVG元素的innerHTML属性。</p>

<p><a name="user-content-append" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#append">#</a> selection.<b>append</b>(<i>name</i>)</p>

<p>在当前选择的每个元素最后追加具有指定名称的新元素，返回包含追加元素的新选择。每个新的元素继承当前元素的数据（如果有的话）和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#select">select</a>相同的方式使用子选择。</p>

<p>这个<em>name</em>可以被指定为一个常量字符串或一个函数，返回追加的DOM元素。当name被指定为一个字符串，它可能有以下形式的命名空间前缀“namespace:tag”。例如，“svg:text”将在svg命名空间创建“text”元素。默认情况下，D3支持svg，xhtml，xlink的，xml和xmlns命名空间。其他的命名空间可以通过添加到<a href="https://github.com/d3/d3/wiki/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4#prefix">d3.ns.prefix</a>注册。如果没有指定命名空间，那么命名空间会从封闭的元素继承；或者，如果该名称是已知的前缀之一，相应的命名空间将被使用（例如，“svg”表示“svg:svg”）。</p>

<p><a name="user-content-insert" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#insert">#</a> selection.<b>insert</b>(<i>name</i>[, <i>before</i>])</p>

<p>在当前选择与指定before选择器匹配的每个元素之前插入具有指定<em>name</em>的新元素，返回包含插入的元素的一个新的选择。如果before选择器不匹配任何元素，那么新元素将用append追加为最后一个子元素。每一个新元素继承当前元素（如果有的话）的数据，子选择（subselections）和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#select">select</a>以同样的方式。 </p>

<p>这个<em>name</em>可以被指定为一个常量字符串或一个函数，返回追加的DOM元素。当<em>name</em>被指定为一个字符串，它可能有以下形式的命名空间前缀“namespace:tag”。例如，“svg:text”将在svg命名空间创建“text”元素。默认情况下，D3支持svg，xhtml，xlink的，xml和xmlns命名空间。其他的命名空间可以通过添加到<a href="https://github.com/d3/d3/wiki/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4#prefix">d3.ns.prefix</a>注册。如果没有指定命名空间，那么命名空间会从封闭的元素继承；或者，如果该名称是已知的前缀之一，相应的命名空间将被使用（例如，“svg”表示“svg:svg”）。</p>

<p>同样地，<em>before</em>选择器可以被指定为一个选择器字符串或一个函数，它返回一个DOM元素。例如，<code>insert("div", ":first-child")</code>将在当前选择前面加上div子节点。对于<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#enter">enter选择器</a>，<em>before</em>选择器在这种情况下也可以省略：输入的元素将被立即插入到更新选择紧随的兄弟元素前（如果有的话）。这使您可以插入DOM的元素与绑定的数据是一致的顺序。但是请注意，如果更新元素修改了顺序，<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#order">selection.order</a>可能仍然需要。</p>

<p><a name="user-content-remove" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#remove">#</a> selection.<b>remove</b>()</p>

<p>删除从当前文档当前选择中的元素。返回“屏幕外（off-screen）”的当前选择（除去了相同的元素），从DOM分离。需要注意的是目前还没有一个专门的API来重新添加删除的元素到文档；然而，你可以通过一个函数来selection.append或selection.insert重新添加元素。</p>

<h3>
<a id="user-content-数据" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E6%95%B0%E6%8D%AE" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>数据</h3>

<p><a name="user-content-data" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">#</a> selection.<b>data</b>([<i>values</i>[, <i>key</i>]])</p>

<p>连接指定的一组数据的和当前选择。指定的<em>values</em>是一组数据值（例如，数字或对象）或一个函数返回一组值。如果没有指定<em>key</em>函数，则<em>values</em>的第一数据被分配到当前选择中第一元素，第二数据分配给当前选择的第二个元素，依此类推。当数据被分配给一个元素，它被存储在属性<code>__data__</code>中，从而使数据“沾粘”，从而使数据可以再选择。</p>

<p><code>data</code>操作的结果是<em>update</em>选择;这表示选择的DOM元素已成功绑定到指定的数据元素。<em>update</em>选择还包含对<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#enter">enter</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#exit">exit</a>的选择，对应于添加和删除数据节点。有关详细信息，请参阅简短的教程<a href="http://bost.ocks.org/mike/join/">关于连接的思考</a></p>

<p><em>key</em>函数可以被指定为控制数据是如何连接元素。这取代默认的by-index行为;<em>key</em>函数被新数据数组中的每个元素调用一次，并再次用于选择中的每个元素。在这两种情况下的<em>key</em>函数是通过传递数据d与索引i。当key 函数上被新的数据元素评价时，<code>this</code>上下文是数据数组；当key 函数被现有选择评估时，<code>this</code>上下文是相关的DOM元素。<em>key</em>函数，基于先前结合的数据返回一个用于连接数据和相关的元素的字符串。例如，如果每个数据都有一个唯一的字段<code>name</code>，该连接可以被指定为<code>.data(data, function(d) { return d.name; })</code>。如果指定了<em>key</em>函数，<code>data</code>操作符也影响节点的索引；该索引被作为第二个参数<code>i</code>作为任何运算符函数的参数。然而，请注意，现有的DOM元素不自动重新排序；根据需要使用<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#sort">sort</a>或<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#order">order</a>函数。有关<em>key</em>函数如何影响数据连接的更详细的示例，请参阅教程<a href="http://bost.ocks.org/mike/bar/2/">条形图2</a></p>

<p>这个<em>values</em>选择中的<strong>每组数据</strong>。因此，如果选择具有多个组（例如，一个<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_selectAll">d3.selectAll</a>后跟一个<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#selectAll">selection.selectAll</a>)），然后data应该被指定为一个函数，该函数返回一个数组（假设你对每个组想要不同的数据）。该函数将被传递的当前组数据（或<code>undefined</code>）和索引，组的<code>this</code>上下文。
例如，可以将一个二维数组和初始选择绑定，然后将包含的内部数组和每个子选择绑定。在这种情况下，<em>values</em>函数是标识函数：它被每个组中的子元素调用，被传递绑定到父元素的数据，并且返回这个数据数组。</p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> matrix <span class="pl-k">=</span> [
  [<span class="pl-c1">11975</span>,  <span class="pl-c1">5871</span>, <span class="pl-c1">8916</span>, <span class="pl-c1">2868</span>],
  [ <span class="pl-c1">1951</span>, <span class="pl-c1">10048</span>, <span class="pl-c1">2060</span>, <span class="pl-c1">6171</span>],
  [ <span class="pl-c1">8010</span>, <span class="pl-c1">16145</span>, <span class="pl-c1">8090</span>, <span class="pl-c1">8045</span>],
  [ <span class="pl-c1">1013</span>,   <span class="pl-c1">990</span>,  <span class="pl-c1">940</span>, <span class="pl-c1">6907</span>]
];

<span class="pl-k">var</span> tr <span class="pl-k">=</span> <span class="pl-smi">d3</span>.<span class="pl-c1">select</span>(<span class="pl-s"><span class="pl-pds">"</span>body<span class="pl-pds">"</span></span>).<span class="pl-c1">append</span>(<span class="pl-s"><span class="pl-pds">"</span>table<span class="pl-pds">"</span></span>).<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>tr<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">data</span>(matrix)
  .<span class="pl-en">enter</span>().<span class="pl-c1">append</span>(<span class="pl-s"><span class="pl-pds">"</span>tr<span class="pl-pds">"</span></span>);

<span class="pl-k">var</span> td <span class="pl-k">=</span> <span class="pl-smi">tr</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>td<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">data</span>(<span class="pl-k">function</span>(<span class="pl-smi">d</span>) { <span class="pl-k">return</span> d; })
  .<span class="pl-en">enter</span>().<span class="pl-c1">append</span>(<span class="pl-s"><span class="pl-pds">"</span>td<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">text</span>(<span class="pl-k">function</span>(<span class="pl-smi">d</span>) { <span class="pl-k">return</span> d; });</pre></div>

<p>如果未指定<em>values</em>，则此方法返回选择中的第一组数据的数组。返回的数组的长度，将与第一组的长度匹配，并且在返回的数组中的每个数据的索引将匹配选择中相应的索引。如果选择的某些元素为null，或者如果他们有没有相关的数据，则数组中的相应元素将是<code>undefined</code>。 </p>

<p>注意：<code>data</code>方法不能用于清除先前结合数据；可以使用<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#datum">selection.datum</a>代替。</p>

<p><a name="user-content-enter" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#enter">#</a> selection.<b>enter()</b></p>

<p>返回输入（enter）选择：当前选择中存在但是当前DOM元素中还不存在的每个数据元素的占位符节点。此方法只在由<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">data</a>运算符返回的更新选择中定义。此外，输入选择只定义了<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#append">append</a>（append），<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#insert">insert</a>（insert），<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#select">select</a>（select）和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#call">call</a>（call）操作符；您必须使用这些操作符在修改任何内容之前实例化输入元素。当你传递函数的参数给这些插入的元素的操作符时，index参数将反映新的位置，而不一定从零开始或者是连续的。 （输入选择也支持<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#empty">empty</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#size">size</a>。） </p>

<p>举一个简单的例子，考虑现有的选择是空的情况下，我们希望创建新的节点来匹配我们的数据：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">d3</span>.<span class="pl-c1">select</span>(<span class="pl-s"><span class="pl-pds">"</span>body<span class="pl-pds">"</span></span>).<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">data</span>([<span class="pl-c1">4</span>, <span class="pl-c1">8</span>, <span class="pl-c1">15</span>, <span class="pl-c1">16</span>, <span class="pl-c1">23</span>, <span class="pl-c1">42</span>])
  .<span class="pl-en">enter</span>().<span class="pl-c1">append</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">text</span>(<span class="pl-k">function</span>(<span class="pl-smi">d</span>) { <span class="pl-k">return</span> d; });</pre></div>

<p>假设body最初是空的，上面的代码将创建六个新的div元素，将它们按顺序追加到body，并指定其文本内容为相应的（强制转为字符串）号码：</p>

<div class="highlight highlight-text-html-basic"><pre>&lt;<span class="pl-ent">div</span>&gt;4&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;8&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;15&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;16&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;23&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;42&lt;/<span class="pl-ent">div</span>&gt;</pre></div>

<p>另一种方式考虑进入的占位符的节点是，它们是指向父节点（在该示例中，就是文档的body）；然而，他们只支持追加和插入。 
当你追加或插入时输入选择并入到<strong>更新选择</strong>。而不是对enter和update选择单独采用同样的操作符，现在你可以一次添加节点后，将其应用到更新选择。如果你发现自己移除整个选择的元素才重新插入其中大部分，用这个来替代。例如：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> update_sel <span class="pl-k">=</span> <span class="pl-smi">svg</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>circle<span class="pl-pds">"</span></span>).<span class="pl-c1">data</span>(data)
<span class="pl-smi">update_sel</span>.<span class="pl-en">attr</span>(<span class="pl-c"><span class="pl-c">/*</span> operate on old elements only <span class="pl-c">*/</span></span>)
<span class="pl-smi">update_sel</span>.<span class="pl-en">enter</span>().<span class="pl-c1">append</span>(<span class="pl-s"><span class="pl-pds">"</span>circle<span class="pl-pds">"</span></span>).<span class="pl-en">attr</span>(<span class="pl-c"><span class="pl-c">/*</span> operate on new elements only <span class="pl-c">*/</span></span>)
<span class="pl-smi">update_sel</span>.<span class="pl-en">attr</span>(<span class="pl-c"><span class="pl-c">/*</span> operate on old and new elements <span class="pl-c">*/</span></span>)
<span class="pl-smi">update_sel</span>.<span class="pl-en">exit</span>().<span class="pl-c1">remove</span>() <span class="pl-c"><span class="pl-c">/*</span> complete the enter-update-exit pattern <span class="pl-c">*/</span></span></pre></div>

<p><a name="user-content-exit" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#exit">#</a> selection.<b>exit()</b></p>

<p>返回退出（exit）选择：找出在当前选择存在的DOM元素中没有新的数据元素时。此方法只被定义在<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">data</a>运算符返回的更新选择。exit选择定义了所有的正常操作符，但通常你主要使用的是<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#remove">remove</a>；其他操作符存在的主要目的是让您可以根据需要定义一个退出的过渡。请注意，exit操作符只是返回一个exit选择引用，由你来删除新节点。 
一个简单的例子，考虑更新在上面的例子中的enter操作符创建的六个DIV元素。在这里，我们把这些元素和一个含有一些新的，一些旧数据的新数组绑定：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> div <span class="pl-k">=</span> <span class="pl-smi">d3</span>.<span class="pl-c1">select</span>(<span class="pl-s"><span class="pl-pds">"</span>body<span class="pl-pds">"</span></span>).<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">data</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>, <span class="pl-c1">16</span>, <span class="pl-c1">32</span>], <span class="pl-k">function</span>(<span class="pl-smi">d</span>) { <span class="pl-k">return</span> d; });</pre></div>

<p>现在div--data操作符的结果--指的是更新的选择。因为我们指定的key函数使用标识函数，并且将新数据数组包含数字[4,8,16]，它也存在旧的数据数组中，这个更新选择包含3 个DIV元素。比方说，我们离开这些元素原样。我们可以实例化并使用enter选择添加新的元素[1,2,32]：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">div</span>.<span class="pl-en">enter</span>().<span class="pl-c1">append</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>)
    .<span class="pl-c1">text</span>(<span class="pl-k">function</span>(<span class="pl-smi">d</span>) { <span class="pl-k">return</span> d; });</pre></div>

<p>同样，我们可以删除退出的元素[15, 23, 42]：
div.exit().remove();</p>

<div class="highlight highlight-text-html-basic"><pre>现在，文档body如下：
&lt;<span class="pl-ent">div</span>&gt;4&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;8&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;16&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;1&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;2&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span>&gt;32&lt;/<span class="pl-ent">div</span>&gt;</pre></div>

<p>注意，DOM元素现在是乱序。然而，选择索引i（操作函数的第二个参数），将正确地与新数据数组相匹配。例如，我们可以指定一个索引属性：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">d3</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>).<span class="pl-en">attr</span>(<span class="pl-s"><span class="pl-pds">"</span>index<span class="pl-pds">"</span></span>, <span class="pl-k">function</span>(<span class="pl-smi">d</span>, <span class="pl-smi">i</span>) { <span class="pl-k">return</span> i; });</pre></div>

<p>结果是：</p>

<div class="highlight highlight-text-html-basic"><pre>&lt;<span class="pl-ent">div</span> <span class="pl-e">index</span>=<span class="pl-s"><span class="pl-pds">"</span>2<span class="pl-pds">"</span></span>&gt;4&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span> <span class="pl-e">index</span>=<span class="pl-s"><span class="pl-pds">"</span>3<span class="pl-pds">"</span></span>&gt;8&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span> <span class="pl-e">index</span>=<span class="pl-s"><span class="pl-pds">"</span>4<span class="pl-pds">"</span></span>&gt;16&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span> <span class="pl-e">index</span>=<span class="pl-s"><span class="pl-pds">"</span>0<span class="pl-pds">"</span></span>&gt;1&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span> <span class="pl-e">index</span>=<span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>&gt;2&lt;/<span class="pl-ent">div</span>&gt;
&lt;<span class="pl-ent">div</span> <span class="pl-e">index</span>=<span class="pl-s"><span class="pl-pds">"</span>5<span class="pl-pds">"</span></span>&gt;32&lt;/<span class="pl-ent">div</span>&gt;</pre></div>

<p>如果你想在文档遍历，以匹配选择数据顺序，可以使用<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#sort">sort</a>或者<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#order">order</a>。</p>

<p><a name="user-content-filter" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#filter">#</a> selection.<b>filter</b>(<i>selector</i>)</p>

<p>过滤选择，返回一个新的选择只包含其指定的<em>selector</em>是true的元素。<em>selector</em>可以被指定为一个函数或作为选择的字符串，如“.foo”。和其他操作符一样，该函数被传递当前数据<code>d</code>和索引<code>i</code>，以及this上下文作为当前的DOM元素。过滤器应该只在选择与DOM元素绑定的时候。例如：从<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#append">append</a>或<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#insert">insert</a>。只绑定的元素和数据的一个子集，可以在<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">data</a>参数中调用内置的数组过滤器<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Filter" title="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Filter">filter</a>。像内置函数一样，D3的过滤器<em>不会</em>在返回选择中保留原来的选择的索引；返回移除元素的副本。如果您想保留的索引，使用<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#select">select</a>代替。 
例如，要选择奇数索引（相对于从零开始的索引）的每一个元素： </p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> odds <span class="pl-k">=</span> <span class="pl-smi">selection</span>.<span class="pl-c1">select</span>(<span class="pl-k">function</span>(<span class="pl-smi">d</span>, <span class="pl-smi">i</span>) { <span class="pl-k">return</span> i <span class="pl-k">&amp;</span> <span class="pl-c1">1</span> <span class="pl-k">?</span> <span class="pl-c1">this</span> <span class="pl-k">:</span> <span class="pl-c1">null</span>; });</pre></div>

<p>等价地，使用的过滤器函数： </p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> odds <span class="pl-k">=</span> <span class="pl-smi">selection</span>.<span class="pl-en">filter</span>(<span class="pl-k">function</span>(<span class="pl-smi">d</span>, <span class="pl-smi">i</span>) { <span class="pl-k">return</span> i <span class="pl-k">&amp;</span> <span class="pl-c1">1</span>; });</pre></div>

<p>或过滤选择器（注意：nth-child伪类是一开始的索引，而不是从零开始的索引）： </p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> odds <span class="pl-k">=</span> <span class="pl-smi">selection</span>.<span class="pl-en">filter</span>(<span class="pl-s"><span class="pl-pds">"</span>:nth-child(even)<span class="pl-pds">"</span></span>);</pre></div>

<p>因此，您可以使用选择或过滤器操作符应用到元素的一个子集上。</p>

<p><a name="user-content-datum" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#datum">#</a> selection.<b>datum</b>([<i>value</i>])</p>

<p>获取或设置每个选定的元素绑定的数据。不像<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">selection.data</a>方法，这种方法不计算一个连接（并因此不计算enter和exit的选择）。此方法在<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#property">selection.property</a>之上实现： </p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">d3</span>.<span class="pl-c1">selection</span>.<span class="pl-c1">prototype</span>.<span class="pl-en">datum</span> <span class="pl-k">=</span> <span class="pl-k">function</span>(<span class="pl-smi">value</span>) {
  <span class="pl-k">return</span> <span class="pl-c1">arguments</span>.<span class="pl-c1">length</span> <span class="pl-k">&lt;</span> <span class="pl-c1">1</span>
      <span class="pl-k">?</span> <span class="pl-c1">this</span>.<span class="pl-en">property</span>(<span class="pl-s"><span class="pl-pds">"</span>__data__<span class="pl-pds">"</span></span>)
      <span class="pl-k">:</span> <span class="pl-c1">this</span>.<span class="pl-en">property</span>(<span class="pl-s"><span class="pl-pds">"</span>__data__<span class="pl-pds">"</span></span>, value);
};</pre></div>

<p>如果指定<em>value</em>，就为所有选中的元素设置元素的绑定数据为指定的值。如果<em>value</em>是一个常数，所有的元素被给予相同的数据；否则，如果<em>value</em>是一个函数，则该函数为每个选定的元素计算，被传递以前的数据<code>d</code>与当前索引<code>i</code>，使用<code>this</code>上下文作为当前的DOM元素。该函数之后被用来确定每个元素的数据。null值将删除绑定的数据。该操作数对索引没有影响。 </p>

<p>如果未指定<em>value</em>，则返回在选择中绑定第一个非空的元素的数据。只有当你知道选择只包含一个元素这通常是很有用的。 </p>

<p>注意：此方法是以前所谓的“map”。旧名已被弃用。 </p>

<p>datum 方法用D3访问HTML5自定义数据属性非常有用。例如，给定下列元素：</p>

<div class="highlight highlight-text-html-basic"><pre>&lt;<span class="pl-ent">ul</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>list<span class="pl-pds">"</span></span>&gt;
  &lt;<span class="pl-ent">li</span> <span class="pl-e">data-username</span>=<span class="pl-s"><span class="pl-pds">"</span>shawnbot<span class="pl-pds">"</span></span>&gt;Shawn Allen&lt;/<span class="pl-ent">li</span>&gt;
  &lt;<span class="pl-ent">li</span> <span class="pl-e">data-username</span>=<span class="pl-s"><span class="pl-pds">"</span>mbostock<span class="pl-pds">"</span></span>&gt;Mike Bostock&lt;/<span class="pl-ent">li</span>&gt;
&lt;/<span class="pl-ent">ul</span>&gt;</pre></div>

<p>你可以公开通过设置每个元素的数据作为内置的<a href="http://www.w3.org/TR/html5/dom.html#dom-dataset" title="http://www.w3.org/TR/html5/dom.html#dom-dataset">dataset</a>属性自定义数据属性D3： </p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">selection</span>.<span class="pl-en">datum</span>(<span class="pl-k">function</span>() { <span class="pl-k">return</span> <span class="pl-c1">this</span>.<span class="pl-smi">dataset</span>; })</pre></div>

<p>这可以用来，例如，按照用户名排序元素。<a href="http://bl.ocks.org/mbostock/1323729">示例</a></p>

<p><a name="user-content-sort" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#sort">#</a> selection.<b>sort</b>([<i>comparator</i>])</p>

<p>根据指定的<em>comparator</em>函数对当前选择的元素排序。比较器函数默认为<a href="https://github.com/mbostock/d3/wiki/Arrays#d3_ascending">d3.ascending</a>，通过传递两个数据元素<em>a</em>和<em>b</em>进行比较，并返回任一负的，正的，或零值。如果为负，则<em>a</em>应该在<em>b</em>之前；如果为正，则<em>a</em>应该为<em>b</em>后；否则a和b被认为是相等的顺序是任意的。需要注意的是，这种排序是不保证是稳定的；然而，它保证与浏览器内置的数组<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort" title="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort">排序</a>方法具有相同的行为。 </p>

<p><a name="user-content-order" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#order">#</a> selection.<b>order</b>()</p>

<p>重新插入元素到文档这样文档顺序选与择顺序就相匹配。这等同于调用sort()如果数据已经排序，但要快得多。</p>

<h3>
<a id="user-content-动画和交互" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E5%8A%A8%E7%94%BB%E5%92%8C%E4%BA%A4%E4%BA%92" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>动画和交互</h3>

<p><a name="user-content-on" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#on">#</a> selection.<b>on</b>(<i>type</i>[, <i>listener</i>[, <i>capture</i>]])</p>

<p>在当前选择的每个元素，为指定的类型<em>type</em>，添加或删除事件监听器<em>listener</em> 。<em>type</em>是一个字符串事件类型的名称，如“点击”，“鼠标悬停”，或“提交”。基本上支持任何<a href="https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events">DOM事件</a>。有关D3支持的事件类型的更多详细信息，请查看Mozilla或Stackoverflow。指定的listener 与其他操作符函数调用方式相同，被传递的当前数据<code>d</code>和索引<code>i</code>与<code>this</code>上下文作为当前的DOM元素。为了在侦听器内访问当前事件，使用全局函数<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_event">d3.event</a>。事件侦听器的返回值将被忽略。</p>

<p>如果所选择的元素相同类型的一个事件监听已经注册了，新的侦听加入之前的现有侦听被除去。为注册相同事件类型的多个监听器，该类型可以跟一个可选的命名空间，如“click.foo”和“click.bar”。
要删除一个监听器，传递null给<em>listener</em>，删除特定事件类型所有监听，传递null给listener，指定<code>.type</code>的类型，如：<code>selection.on(".foo", null)</code>。 </p>

<p>一个可选的捕获<em>capture</em>标志可以指定，对应于W3C的<a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration" title="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">useCapture标志</a>：“开始捕获后，所有指定类型的事件将被分派到注册的EventListener在被分派到事件树任何EventTargets下，事件是沿着树向上冒泡而不会触发一个EventListener指定使用捕获”。</p>

<p>如果未指定监听器，指定类型（如果有）返回当前分配的监听器。</p>

<p><a name="user-content-d3_event" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_event">#</a> d3.<b>event</b></p>

<p>存储当前的事件（如果有的话）。这个全局函数是在事件侦听器回调过程中使用<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#on">on</a>操作符注册的。当监听器在<code>finally</code>块被通知后当前事件被重置。这使侦听器函数与其他操作符函数具有相同的形式，传递当前数据<code>d</code>和索引<code>i</code>。
<code>d3.event</code>对象是<a href="https://developer.mozilla.org/en-US/docs/DOM/event" title="https://developer.mozilla.org/en-US/docs/DOM/event">DOM事件</a>，并实现了标准事件字段，像时间戳<code>timeStamp</code>和键代码<code>keyCode</code>，以及<code>preventDefault()</code>方法和的<code>stopPropagation()</code>方法。当然你可以使用原生事件的<a href="https://developer.mozilla.org/en/DOM/event.pageX" title="https://developer.mozilla.org/en/DOM/event.pageX">pageX</a> and <a href="https://developer.mozilla.org/en/DOM/event.pageY" title="https://developer.mozilla.org/en/DOM/event.pageY">pageY</a>，它往往更方便转变事件位置为接收该事件容器的局部坐标系。例如，如果你在网页的正常流程嵌入SVG，你可能想事件的位置是相对于SVG图像的左上角的。如果您的SVG包含转换，你也可能想知道事件的相对于那些变换的位置。标准鼠标指针使用<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_mouse">d3.mouse</a>运算符，<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_touches">d3.touches</a>用在iOS多点触控事件上。</p>

<p><a name="user-content-d3_mouse" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_mouse">#</a> d3.<b>mouse</b>(<i>container</i>)</p>

<p>返回当前<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_event">d3.event</a>相对于指定的容器的x和y坐标，。该容器可以是一个HTML或SVG容器元素，如<a href="http://www.w3.org/TR/SVG/struct.html#Groups" title="http://www.w3.org/TR/SVG/struct.html#Groups">svg:g</a>或<a href="http://www.w3.org/TR/SVG/struct.html#SVGElement" title="http://www.w3.org/TR/SVG/struct.html#SVGElement">svg:svg</a>。该坐标返回为一个包含两个元素的数组[<em>x</em>, <em>y</em>]。</p>

<p><a name="user-content-d3_touch" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_touch">#</a> d3.<b>touch</b>(<i>container</i>[, <i>touches</i>], <i>identifier</i>)</p>

<p>返回指定标识符触摸当前<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_event">d3.event</a>相应的x和y坐标，相对于指定容器。如果未指定<em>touches</em>时，默认为当前事件的<a href="http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html#//apple_ref/javascript/instp/TouchEvent/changedTouches" title="http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html#//apple_ref/javascript/instp/TouchEvent/changedTouches">changedTouches</a>。该容器可以是一个HTML或SVG容器元件，如一个的svg:g或svg:svg。坐标被返回为两元素数组的数组[ [ <em>x1</em>, <em>y1</em>], [ <em>x2</em>, <em>y2</em>], … ]。如果在指定的标识符<em>touches</em>没有接触，则返回null；这对于忽略touchmove那些只是touches移动了的事件是很有用的。</p>

<p><a name="user-content-d3_touches" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_touches">#</a> d3.<b>touches</b>(<i>container</i>[, <i>touches</i>])</p>

<p>返回与当前<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_event">d3.event</a>相关联的每个触摸<em>x</em>和<em>y</em>坐标，基于<a href="http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html#//apple_ref/javascript/instp/TouchEvent/touches" title="http://developer.apple.com/library/safari/documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html#//apple_ref/javascript/instp/TouchEvent/touches">touches</a>属性，相对于指定的容器中。该容器可以是一个HTML或SVG容器元素，如svg:g 或 svg:svg。坐标返回两个元素的数组的数组[ [ <em>x1</em>, <em>y1</em>], [ <em>x2</em>, <em>y2</em>], … ]。如果指定了触摸，返回指定触摸的位置，如果没有指定<em>touches</em>时，则默认为当前事件的<code>touches</code>属性。</p>

<p><a name="user-content-transition" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#transition">#</a> selection.<b>transition</b>([<i>name</i>])</p>

<p>开始为当前选择的<a href="https://github.com/d3/d3/wiki/Transitions">过渡</a>。转换的行为很像选择，除了操作符动画平滑的随着时间的推移，而不是瞬间完成。</p>

<p><a name="user-content-interrupt" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#interrupt">#</a> selection.<b>interrupt</b>([<i>name</i>])</p>

<p>立即中断当前的<a href="https://github.com/d3/d3/wiki/Transitions">过渡</a>（如果有的话）。不会取消任何尚未启动的预定的转变。最好要取消原定过渡，简单地创建中断当前的过渡后，一个新的零延迟过渡：</p>

<div class="highlight highlight-source-js"><pre>selection
    .<span class="pl-en">interrupt</span>() <span class="pl-c"><span class="pl-c">//</span> 取消当前过渡</span>
    .<span class="pl-en">transition</span>(); <span class="pl-c"><span class="pl-c">//</span>抢占任何预定的转换</span></pre></div>

<h3>
<a id="user-content-子选择" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E5%AD%90%E9%80%89%E6%8B%A9" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>子选择</h3>

<p>顶层的select方法查询整个文档，一个选择的<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#select">select</a>和<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#selectAll">selectAll</a>操作符限定查询每个选定元素的后代；我们称之为“部分选择”。例如，<code>d3.selectAll("p").select("b")</code>返回在每一个段落("p")元素中的第一个bold("b")元素。部分选择通过selectAll通过祖先分组元素。因此，<code>d3.selectAll("p").selectAll("b")</code>。通过段落分组而d3.selectAll("p b") 返回一个扁平的选择。部分选择通过select是相似的，但保留了团体和传播数据。分组起在数据连接中起重要的作用，和功能性操作符可依赖于其组内的当前元素的数值索引。</p>

<p><a name="user-content-select" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#select">#</a> selection.<b>select</b>(<i>selector</i>)</p>

<p>对当前选中的每个元素，选中第一个匹配特定的选择器字符串<em>selector</em>的子代元素。如果当前元素没有元素匹配特定的选择器，当前索引处的元素在返回的选择中将是空值null。运算符（除了<a href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#data">data</a>）自动跳过null元素，从而保持现有选择的索引。如果当前元素具有相关联的数据，该数据由返回的子选择继承，并且自动绑定到新选定的元素。如果有多个元素匹配选择器，只有在文档遍历顺序中第一个匹配的元素会被选中。选择器也可以被指定为一个函数，返回一个元素，或者null（如果没有匹配的元素）。在这种情况下，指定的选择器以和其他操作函数同样的方式被调用，被传递的当前数据<code>d</code>和索引<code>i</code>，与<code>this</code>上下文作为当前的DOM元素。 </p>

<p><a name="user-content-selectAll" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#selectAll">#</a> selection.<b>selectAll</b>(<i>selector</i>)</p>

<p>对当前选择的每个元素，选取匹配指定选择器字符串的后代元素。返回的选择是通过在当前选择的祖先节点进行分组。如果没有元素和当前元素的指定选择器相匹配，返回的选择中当前索引处的组将是null。部分选取不从当前选择继承数据，但如果数据值指定为一个函数，这个函数会被调用，带有的祖先节点的数据d和组索引i来确定部分选定的数据绑定。 </p>

<p>通过selectAll的分组也将影响后续进入的占位节点。因此，为追加进入的节点指定父节点，使用select后紧跟selectAll： </p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">d3</span>.<span class="pl-c1">select</span>(<span class="pl-s"><span class="pl-pds">"</span>body<span class="pl-pds">"</span></span>).<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>)</pre></div>

<p>您可以通过检查各组数据的parentNode属性查看每个组的父节点，例如selection[0].parentNode。 </p>

<p>选择器也可以被指定为一个函数，返回元素的数组（或节点列表NodeList），或者空数组（如果没有匹配的元素）。在这种情况下，指定的选择器以和其他操作函数同样的方式被调用，被传递的当前数据<code>d</code>和索引<code>i</code>，与<code>this</code>上下文作为当前的DOM元素。 </p>

<h3>
<a id="user-content-控制" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E6%8E%A7%E5%88%B6" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>控制</h3>

<p>对于高级用法，D3有一些额外的用户控制流操作符。</p>

<p><a name="user-content-each" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#each">#</a> selection.<b>each</b>(<i>function</i>)</p>

<p>为当前选择的每个元素，调用指定的函数，传递当前数据<code>d</code>和索引<code>i</code>，与当前的DOM元素的<code>this</code>上下文。这个操作符几乎被所有的其他操作符内部使用，并可以用于调用任意代码为每个选定的元素。<code>each</code>操作符可以用来处理递归的选择，通过在回调函数内使用<code>d3.select(this)</code>。</p>

<p><a name="user-content-call" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#call">#</a> selection.<b>call</b>(<i>function</i>[, <i>arguments…</i>])</p>

<p>调用指定的函数一次，通过在当前的选择以及任何可选参数。无论指定函数的返回值是什么，call操作符总是返回当前的选择。通过call调用函数与手动调用函数是完全一样的；但它可以更容易地使用方法链。例如，假设我们要在许多不同的地方以同样的方式设置一些属性。我们采取的代码，把它包在一个可重复使用的功能：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">function</span> <span class="pl-en">foo</span>(<span class="pl-smi">selection</span>) {
  selection
      .<span class="pl-en">attr</span>(<span class="pl-s"><span class="pl-pds">"</span>name1<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>value1<span class="pl-pds">"</span></span>)
      .<span class="pl-en">attr</span>(<span class="pl-s"><span class="pl-pds">"</span>name2<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>value2<span class="pl-pds">"</span></span>);
}</pre></div>

<p>现在我们可以这样写：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-en">foo</span>(<span class="pl-smi">d3</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>));</pre></div>

<p>或者等价的方式：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">d3</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>div<span class="pl-pds">"</span></span>).<span class="pl-c1">call</span>(foo);</pre></div>

<p>被调用函数的<code>this</code>上下文也是当前的选择。第一个参数是略显多余的，这我们可能在未来解决。 
如果您使用的<code>selection.call</code>的对象，方法和需要<code>this</code>指向该对象创建之前调用绑定到对象的函数。</p>

<div class="highlight highlight-source-js"><pre><span class="pl-k">function</span> <span class="pl-en">Foo</span>(<span class="pl-smi">text</span>) {
    <span class="pl-c1">this</span>.<span class="pl-c1">text</span> <span class="pl-k">=</span> text;
}

<span class="pl-smi">Foo</span>.<span class="pl-c1">prototype</span>.<span class="pl-en">setText</span> <span class="pl-k">=</span> <span class="pl-k">function</span>(<span class="pl-smi">selection</span>) {
    <span class="pl-smi">selection</span>.<span class="pl-c1">text</span>(<span class="pl-c1">this</span>.<span class="pl-c1">text</span>);
}

<span class="pl-k">var</span> bar <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">Foo</span>(<span class="pl-s"><span class="pl-pds">"</span>Bar<span class="pl-pds">"</span></span>);

<span class="pl-smi">d3</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>span<span class="pl-pds">"</span></span>).<span class="pl-c1">call</span>(<span class="pl-smi">bar</span>.<span class="pl-smi">setText</span>.<span class="pl-en">bind</span>(bar));
<span class="pl-c"><span class="pl-c">//</span> Or</span>
<span class="pl-smi">d3</span>.<span class="pl-en">selectAll</span>(<span class="pl-s"><span class="pl-pds">"</span>span<span class="pl-pds">"</span></span>).<span class="pl-c1">call</span>(<span class="pl-smi">Foo</span>.<span class="pl-c1">prototype</span>.<span class="pl-smi">setText</span>.<span class="pl-en">bind</span>(bar));</pre></div>

<p><a name="user-content-empty" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#empty">#</a> selection.<b>empty</b>()</p>

<p>返回true如果当前选择为空；一个选择是空的，如果它不包含任何元素或null元素。</p>

<p><a name="user-content-node" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#node">#</a> selection.<b>node</b>()</p>

<p>返回当前选择的第一个非空的元素。如果选择为空，则返回null。 </p>

<p><a name="user-content-size" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#size">#</a> selection.<b>size</b>()</p>

<p>Returns the total number of elements in the current selection.</p>

<h3>
<a id="user-content-扩展" class="anchor" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#%E6%89%A9%E5%B1%95" aria-hidden="true"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>扩展</h3>

<p><a name="user-content-d3_selection" href="https://github.com/d3/d3/wiki/%E9%80%89%E6%8B%A9%E5%99%A8#d3_selection">#</a> d3.<b>selection</b>()</p>

<p>返回根的选择，相当于<code>d3.select(document.documentElement)</code>。此函数还可以用于检查一个对象是一个选择：<code>o instanceof d3.selection</code>。您还可以添加新的方法到选择的原形中。例如，添加一个便捷的方法，用于设置复选框的<code>checked</code>属性，你可能这样写：</p>

<div class="highlight highlight-source-js"><pre><span class="pl-smi">d3</span>.<span class="pl-c1">selection</span>.<span class="pl-c1">prototype</span>.<span class="pl-en">checked</span> <span class="pl-k">=</span> <span class="pl-k">function</span>(<span class="pl-smi">value</span>) {
  <span class="pl-k">return</span> <span class="pl-c1">arguments</span>.<span class="pl-c1">length</span> <span class="pl-k">&lt;</span> <span class="pl-c1">1</span>
      <span class="pl-k">?</span> <span class="pl-c1">this</span>.<span class="pl-en">property</span>(<span class="pl-s"><span class="pl-pds">"</span>checked<span class="pl-pds">"</span></span>)
      <span class="pl-k">:</span> <span class="pl-c1">this</span>.<span class="pl-en">property</span>(<span class="pl-s"><span class="pl-pds">"</span>checked<span class="pl-pds">"</span></span>, value);
};  </pre></div>

<hr>

<table>
<thead>
<tr>
<th>本文参与</th>
<th>人员</th>
<th>组织</th>
<th>时间</th>
</tr>
</thead>
<tbody>
<tr>
<td>翻译</td>
<td><a href="https://github.com/tianxuzhang">大傻</a></td>
<td><a href="https://github.com/VisualCrew">VisualCrew小组</a></td>
<td>20141102</td>
</tr>
<tr>
<td>校对/排版</td>
<td><a href="https://github.com/tianxuzhang">大傻</a></td>
<td><a href="https://github.com/VisualCrew">VisualCrew小组</a></td>
<td>2015-11-02T12:00:51Z</td>
</tr>
<tr>
<td>校对</td>
<td><a href="https://github.com/liang42hao">liang42hao</a></td>
<td><a href="https://github.com/VisualCrew">VisualCrew小组</a></td>
<td>2016-03-04T16:36:18Z</td>
</tr>
</tbody>
</table>

      </div>

  </div>
  </div>
</div>
</div>


  </div>
  <div class="modal-backdrop js-touch-events"></div>
</div>


    </div>
  </div>

    </div>

        <div class="container site-footer-container">
  <div class="site-footer" role="contentinfo">
    <ul class="site-footer-links float-right">
        <li><a href="https://github.com/contact" data-ga-click="Footer, go to contact, text:contact">Contact GitHub</a></li>
      <li><a href="https://developer.github.com/" data-ga-click="Footer, go to api, text:api">API</a></li>
      <li><a href="https://training.github.com/" data-ga-click="Footer, go to training, text:training">Training</a></li>
      <li><a href="https://shop.github.com/" data-ga-click="Footer, go to shop, text:shop">Shop</a></li>
        <li><a href="https://github.com/blog" data-ga-click="Footer, go to blog, text:blog">Blog</a></li>
        <li><a href="https://github.com/about" data-ga-click="Footer, go to about, text:about">About</a></li>

    </ul>

    <a href="https://github.com/" aria-label="Homepage" class="site-footer-mark" title="GitHub">
      <svg aria-hidden="true" class="octicon octicon-mark-github" height="24" version="1.1" viewBox="0 0 16 16" width="24"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
</a>
    <ul class="site-footer-links">
      <li>© 2017 <span title="0.25126s from github-fe138-cp1-prd.iad.github.net">GitHub</span>, Inc.</li>
        <li><a href="https://github.com/site/terms" data-ga-click="Footer, go to terms, text:terms">Terms</a></li>
        <li><a href="https://github.com/site/privacy" data-ga-click="Footer, go to privacy, text:privacy">Privacy</a></li>
        <li><a href="https://github.com/security" data-ga-click="Footer, go to security, text:security">Security</a></li>
        <li><a href="https://status.github.com/" data-ga-click="Footer, go to status, text:status">Status</a></li>
        <li><a href="https://help.github.com/" data-ga-click="Footer, go to help, text:help">Help</a></li>
    </ul>
  </div>
</div>



    

    <div id="ajax-error-message" class="ajax-error-message flash flash-error">
      <svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.865 1.52c-.18-.31-.51-.5-.87-.5s-.69.19-.87.5L.275 13.5c-.18.31-.18.69 0 1 .19.31.52.5.87.5h13.7c.36 0 .69-.19.86-.5.17-.31.18-.69.01-1L8.865 1.52zM8.995 13h-2v-2h2v2zm0-3h-2V6h2v4z"></path></svg>
      <button type="button" class="flash-close js-flash-close js-ajax-error-dismiss" aria-label="Dismiss error">
        <svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
      </button>
      You can't perform that action at this time.
    </div>


      
      
      
      
      
        

      
    <div class="js-stale-session-flash stale-session-flash flash flash-warn flash-banner d-none">
      <svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.865 1.52c-.18-.31-.51-.5-.87-.5s-.69.19-.87.5L.275 13.5c-.18.31-.18.69 0 1 .19.31.52.5.87.5h13.7c.36 0 .69-.19.86-.5.17-.31.18-.69.01-1L8.865 1.52zM8.995 13h-2v-2h2v2zm0-3h-2V6h2v4z"></path></svg>
      <span class="signed-in-tab-flash">You signed in with another tab or window. <a href="选择器 · d3_d3 Wiki_files/选择器 · d3_d3 Wiki.html">Reload</a> to refresh your session.</span>
      <span class="signed-out-tab-flash">You signed out in another tab or window. <a href="选择器 · d3_d3 Wiki_files/选择器 · d3_d3 Wiki.html">Reload</a> to refresh your session.</span>
    </div>
    <div class="facebox" id="facebox" style="display:none;">
  <div class="facebox-popup">
    <div class="facebox-content" role="dialog" aria-labelledby="facebox-header" aria-describedby="facebox-description">
    </div>
    <button type="button" class="facebox-close js-facebox-close" aria-label="Close modal">
      <svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
    </button>
  </div>
</div>

  


</body></html>